<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-service-edit"
			th:object="${service}">
			<input id="serviceId" name="serviceId" th:field="*{serviceId}"
				type="hidden">
			<div class="form-group">
				<label class="col-sm-3 control-label">服务项目名称：</label>
				<div class="col-sm-8">
					<input id="serviceName" name="serviceName"
						th:field="*{serviceName}" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">服务价格：</label>
				<div class="col-sm-8">
					<input id="servicePrice" name="servicePrice"
						th:field="*{servicePrice}" class="form-control" type="text">
				</div>
			</div>
			<!-- 修改服务类型 -->
			<div class="form-group">
				<input type="hidden" th:value="*{tosId}" id="tosIdVal"> <label
					class="col-sm-3 control-label">服务类型：</label>
				<div class="col-sm-8">
					<select id="tosId" name="tosId" class="dropdown-header">

					</select>
				</div>

			</div>


			<!-- <div class="form-group">	
				<label class="col-sm-3 control-label">备注：</label>
				<div class="col-sm-8">
					<input id="remark" name="remark" th:field="*{remark}" class="form-control" type="text">
				</div>
			</div> -->

		</form>
	</div>
	<div th:include="include::footer"></div>
	<script type="text/javascript">
		
		$("#form-service-edit").validate({
			rules:{
				serviceName:{
					required:true,
				},
		servicePrice:{
			required:true,
			checkMoney:true
		}}
		});
		$.validator.addMethod("checkMoney",function(value,element,params){  
            var checkMoney = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;  
            return this.optional(element)||(checkMoney.test(value));  
        },"请输入正确的金钱格式");
		function submitHandler() {
	        if ($.validate.form()) {
	            $.operate.save("/service/edit", $('#form-service-edit').serialize());
	        }
	    }
	    
	    //下拉框
		 tosName();
         function tosName(){
         	$.ajax({
                 type: "post",
                 url: "/service/selectTosName",
                 dataType: "json",
                 success: function(res){
                     if (null != res) {
                        var html= '';
                         Object.keys(res).forEach(function(key){
                             html += '<option value="' + res[key].tosId + '" label="'+ res[key].tosName+'"></option>';
                         });
                         $('#tosId').html(html);
						 $('#tosId').addClass("form-control");
                         var Flag=$("#tosIdVal").val();
                         //根据值让option选中 
                             $("#tosId option[value='"+Flag+"']").attr("selected","selected");
                  
                     }
                     }
              });
         }
	</script>
</body>
</html>
